<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * 同步代码：
       * console.log("script start");
       * console.log("async1");
       * console.log("async2");
       *
       * console.log("promise");
       * console.log("script end");
       * 微任务队列：
       *
       * console.log("async1 end");
       * console.log("promise2");
       * 宏任务队列：
       * console.log("setTimeOut");
       */
      async function async1() {
        console.log("async1");
        await async2();
        console.log("async1 end"); // 这段代码会被放入微任务队列
      }
      async function async2() {
        console.log("async2");
      }
      console.log("script start");
      setTimeout(() => {
        console.log("setTimeOut");
      }, 0);
      async1();
      new Promise((resolve) => {
        console.log("promise");
        resolve();
      }).then(() => {
        console.log("promise2");
      });
      console.log("script end");

    </script>
  </body>
</html>
